




/*
'===============================================================================
'  HNG.Portal.BL.TblSanPhamKhuyenMaiManagerBase
'===============================================================================
*/

using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using HNG.Portal.BLL;
using HNG.Portal.DAL;
using HNG.Portal.DAL.EntityClasses;
using HNG.Portal.DAL.FactoryClasses;
using HNG.Portal.DAL.HelperClasses;
using SD.LLBLGen.Pro.ORMSupportClasses;
using System.Windows.Forms;
namespace HNG.Portal.BLL
{
	public class TblSanPhamKhuyenMaiManagerBase
	{
	    
		#region ColumnNames
		
				public const String Field_Id="Id";
				
				public const String Field_IdsanPham="IdsanPham";
				
				public const String Field_IdsanPhamKhuyenMai="IdsanPhamKhuyenMai";
				
		#endregion	
		/// <summary>
		/// Purpose: Class constructor.
		/// </summary>
		public TblSanPhamKhuyenMaiManagerBase()
		{
			// Nothing for now.
		}
		public DataTable Clone()
		{
			DataTable dt = new DataTable();
						
			
			dt.Columns.Add(Field_Id,typeof(int));
			
						
			
			dt.Columns.Add(Field_IdsanPham,typeof(int));
			
						
			
			dt.Columns.Add(Field_IdsanPhamKhuyenMai,typeof(int));
			
			            
            return dt;			
		}
			
		public TblSanPhamKhuyenMaiEntity Convert_Entity(TblSanPhamKhuyenMaiEntity _TblSanPhamKhuyenMaiEntity,TblSanPhamKhuyenMaiEntity _TblSanPhamKhuyenMaiEntity_XML)
		{	
			
				
			_TblSanPhamKhuyenMaiEntity.Id= _TblSanPhamKhuyenMaiEntity_XML.Id;
				
			_TblSanPhamKhuyenMaiEntity.IdsanPham= _TblSanPhamKhuyenMaiEntity_XML.IdsanPham;
				
			_TblSanPhamKhuyenMaiEntity.IdsanPhamKhuyenMai= _TblSanPhamKhuyenMaiEntity_XML.IdsanPhamKhuyenMai;
				
			
			return _TblSanPhamKhuyenMaiEntity;
		}	
		
			
		public void InsertCollection(EntityCollection _Collection)
		{
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
            {
                adapter.SaveEntityCollection(_Collection);
            }
		}

		public TblSanPhamKhuyenMaiEntity Insert(TblSanPhamKhuyenMaiEntity TblSanPhamKhuyenMaiEntity)
		{
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.SaveEntity(TblSanPhamKhuyenMaiEntity, true);
			}
			return TblSanPhamKhuyenMaiEntity;
		}

		
		public TblSanPhamKhuyenMaiEntity Insert(int Id, int IdsanPham, int IdsanPhamKhuyenMai)
		{
			TblSanPhamKhuyenMaiEntity _TblSanPhamKhuyenMaiEntity = new TblSanPhamKhuyenMaiEntity();
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				
				_TblSanPhamKhuyenMaiEntity.Id = Id;
				_TblSanPhamKhuyenMaiEntity.IdsanPham = IdsanPham;
				_TblSanPhamKhuyenMaiEntity.IdsanPhamKhuyenMai = IdsanPhamKhuyenMai;
				adapter.SaveEntity(_TblSanPhamKhuyenMaiEntity, true);
			}
			return _TblSanPhamKhuyenMaiEntity;
		}

		public TblSanPhamKhuyenMaiEntity Insert(int IdsanPham, int IdsanPhamKhuyenMai)
		{
			TblSanPhamKhuyenMaiEntity _TblSanPhamKhuyenMaiEntity = new TblSanPhamKhuyenMaiEntity();
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				
				_TblSanPhamKhuyenMaiEntity.IdsanPham = IdsanPham;
				_TblSanPhamKhuyenMaiEntity.IdsanPhamKhuyenMai = IdsanPhamKhuyenMai;
				adapter.SaveEntity(_TblSanPhamKhuyenMaiEntity, true);
			}
			return _TblSanPhamKhuyenMaiEntity;
		}

		public bool Update(TblSanPhamKhuyenMaiEntity _TblSanPhamKhuyenMaiEntity)
		{
			bool toReturn = false;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				RelationPredicateBucket filter = new RelationPredicateBucket();
				IPredicateExpression _PredicateExpression = new PredicateExpression();
				_PredicateExpression.Add(TblSanPhamKhuyenMaiFields.Id == _TblSanPhamKhuyenMaiEntity.Id);
					
				filter.PredicateExpression.Add(_PredicateExpression);

				adapter.UpdateEntitiesDirectly(_TblSanPhamKhuyenMaiEntity, filter);
				toReturn = true;
			}
			return toReturn;
		}
		
		public bool Update(TblSanPhamKhuyenMaiEntity _TblSanPhamKhuyenMaiEntity, RelationPredicateBucket filter)
		{
			bool toReturn = false;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.UpdateEntitiesDirectly(_TblSanPhamKhuyenMaiEntity, filter);
				toReturn = true;
			}
			return toReturn;
		}

		public bool Update(int Id, int IdsanPham, int IdsanPhamKhuyenMai)
		{
			bool toReturn = false;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				TblSanPhamKhuyenMaiEntity _TblSanPhamKhuyenMaiEntity = new TblSanPhamKhuyenMaiEntity(Id);
				if (adapter.FetchEntity(_TblSanPhamKhuyenMaiEntity))
				{
				
					_TblSanPhamKhuyenMaiEntity.IdsanPham = IdsanPham;
					_TblSanPhamKhuyenMaiEntity.IdsanPhamKhuyenMai = IdsanPhamKhuyenMai;
					adapter.SaveEntity(_TblSanPhamKhuyenMaiEntity, true);
					toReturn = true;
				}
			}
			return toReturn;
		}

		public bool Delete(int Id)
		{
			bool toReturn = false;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				TblSanPhamKhuyenMaiEntity _TblSanPhamKhuyenMaiEntity = new TblSanPhamKhuyenMaiEntity(Id);
				if (adapter.FetchEntity(_TblSanPhamKhuyenMaiEntity))
				{
					adapter.DeleteEntity(_TblSanPhamKhuyenMaiEntity);
					toReturn = true;
				}
			}
			return toReturn;
		}
		
		public void DeleteAll() 
		{
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.DeleteEntitiesDirectly("TblSanPhamKhuyenMaiEntity", null);
			}
		}
		
		
		public int DeleteById(int Id)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblSanPhamKhuyenMaiFields.Id == Id);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("TblSanPhamKhuyenMaiEntity", filter);
			}
			return toReturn;
		}
		
		public int DeleteByIdsanPham(int IdsanPham)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblSanPhamKhuyenMaiFields.IdsanPham == IdsanPham);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("TblSanPhamKhuyenMaiEntity", filter);
			}
			return toReturn;
		}
		
		public int DeleteByIdsanPhamKhuyenMai(int IdsanPhamKhuyenMai)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblSanPhamKhuyenMaiFields.IdsanPhamKhuyenMai == IdsanPhamKhuyenMai);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("TblSanPhamKhuyenMaiEntity", filter);
			}
			return toReturn;
		}
		

		
		public TblSanPhamKhuyenMaiEntity SelectOne(int Id)
		{
			TblSanPhamKhuyenMaiEntity toReturn = null;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				TblSanPhamKhuyenMaiEntity _TblSanPhamKhuyenMaiEntity = new TblSanPhamKhuyenMaiEntity(Id);
				if (adapter.FetchEntity(_TblSanPhamKhuyenMaiEntity))
				{
					toReturn = _TblSanPhamKhuyenMaiEntity;
				}
			}
			return toReturn;
		}

		// Return EntityCollection
		public EntityCollection SelectAll()
		{
			EntityCollection _TblSanPhamKhuyenMaiCollection = new EntityCollection( new TblSanPhamKhuyenMaiEntityFactory());
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_TblSanPhamKhuyenMaiCollection, null, 0, null);
			}
			return _TblSanPhamKhuyenMaiCollection;
		}
		
		// Return DataTable
		public DataTable SelectAllRDT()
		{
			DataTable toReturn = new DataTable();
			EntityCollection _TblSanPhamKhuyenMaiCollection = new EntityCollection(new TblSanPhamKhuyenMaiEntityFactory());
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_TblSanPhamKhuyenMaiCollection.EntityFactoryToUse.CreateFields(), toReturn, null, true);
			}
			return toReturn;
		}

		
		// Return EntityCollection
		public EntityCollection SelectById(int Id)
		{
			EntityCollection _TblSanPhamKhuyenMaiCollection = new EntityCollection(new TblSanPhamKhuyenMaiEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblSanPhamKhuyenMaiFields.Id == Id);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_TblSanPhamKhuyenMaiCollection, filter, 0, null);
			}
			return _TblSanPhamKhuyenMaiCollection;
		}
		
		// Return DataTable
		public DataTable SelectByIdRDT(int Id)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _TblSanPhamKhuyenMaiCollection = new EntityCollection(new TblSanPhamKhuyenMaiEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblSanPhamKhuyenMaiFields.Id == Id);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_TblSanPhamKhuyenMaiCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		// Return EntityCollection
		public EntityCollection SelectByIdsanPham(int IdsanPham)
		{
			EntityCollection _TblSanPhamKhuyenMaiCollection = new EntityCollection(new TblSanPhamKhuyenMaiEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblSanPhamKhuyenMaiFields.IdsanPham == IdsanPham);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_TblSanPhamKhuyenMaiCollection, filter, 0, null);
			}
			return _TblSanPhamKhuyenMaiCollection;
		}
		
		// Return DataTable
		public DataTable SelectByIdsanPhamRDT(int IdsanPham)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _TblSanPhamKhuyenMaiCollection = new EntityCollection(new TblSanPhamKhuyenMaiEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblSanPhamKhuyenMaiFields.IdsanPham == IdsanPham);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_TblSanPhamKhuyenMaiCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		// Return EntityCollection
		public EntityCollection SelectByIdsanPhamKhuyenMai(int IdsanPhamKhuyenMai)
		{
			EntityCollection _TblSanPhamKhuyenMaiCollection = new EntityCollection(new TblSanPhamKhuyenMaiEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblSanPhamKhuyenMaiFields.IdsanPhamKhuyenMai == IdsanPhamKhuyenMai);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_TblSanPhamKhuyenMaiCollection, filter, 0, null);
			}
			return _TblSanPhamKhuyenMaiCollection;
		}
		
		// Return DataTable
		public DataTable SelectByIdsanPhamKhuyenMaiRDT(int IdsanPhamKhuyenMai)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _TblSanPhamKhuyenMaiCollection = new EntityCollection(new TblSanPhamKhuyenMaiEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblSanPhamKhuyenMaiFields.IdsanPhamKhuyenMai == IdsanPhamKhuyenMai);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_TblSanPhamKhuyenMaiCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		

	}
}
